package ca.kooki.codesnippet.core;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;

public class SystemDate {

  
  //```````````````````````
  // STATIC VARIABLES
  //```````````````````````

  private static boolean _hasInternalNow;
  private static Date _internalNow;

  //```````````````````````
  // INTERFACE
  //```````````````````````
  
  public static void reset()
  {
    _hasInternalNow = false;
  }
  
  public static Date Now()
  {
    return _hasInternalNow ? _internalNow : new Date();
  }
  
  public static void setNowTo(Date when)
  {
    _hasInternalNow = true;
    _internalNow = when;
  }
  
  public static void setNowTo(String input) throws ParseException
  {
    Date when = parse(input);
    setNowTo(when);
  }
  
  public static Date parse(String input) throws ParseException
  {
    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
    return format.parse(input);
  }
  
  public static String formatDate(Date when)
  {
    DateFormat format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
    return format.format(when);
  }
  
  public static boolean areSimilar(Date one, Date two)
  {
    return formatDate(one).equals(formatDate(two));
  }
  
}
